home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / programming / mui / mcc_pkb / developer / c / examples / pkb-demo.c next >
C/C++ Source or Header  |  1999-06-14  |  8KB  |  279 lines

  1. #define MUI_OBSOLETE
  2.  
  3. #include <exec/types.h>
  4. #include <exec/memory.h>
  5. #define ASM
  6. #define Prototype  extern
  7. #define Local      static
  8.  
  9. #ifdef __STORM__
  10. #define REG(x)     register __ ## x
  11. #define SAVEDS     __saveds
  12. #define __stkargs
  13. #define __argargs
  14. #else
  15. #ifdef _DCC
  16. #define REG(x)     __ ## x
  17. #define SAVEDS     __geta4
  18. #endif
  19. #endif
  20.  
  21. #ifndef MAKE_ID
  22. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  23. #endif
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <clib/alib_protos.h>
  28. #include <libraries/mui.h>
  29.  
  30. #ifdef __STORM__
  31. #include <pragma/muimaster_lib.h>
  32. #include <pragma/exec_lib.h>
  33. #include <pragma/utility_lib.h>
  34. #else
  35. #ifdef _DCC
  36. #include <proto/muimaster.h>
  37. #include <clib/exec_protos.h>
  38. #include <clib/utility_protos.h>
  39. #endif
  40. #endif
  41.  
  42. #include "mui/pkb_mcc.h"
  43.  
  44.  
  45. Local     void fail( APTR, char * );
  46. Local     void init( void );
  47. int main( int, STRPTR * );
  48.  
  49. int
  50. wbmain(struct WBStartup *wb_startup)
  51. {
  52.      return (main(0, (STRPTR *)wb_startup));
  53. }
  54.  
  55. struct Library  *MUIMasterBase   = NULL;
  56.  
  57. int
  58. main(int argc, STRPTR argv[])
  59. {
  60.      APTR  app,
  61.         window,
  62.         PianoKeyboard,PKbsmall,
  63.         cx,ch,cq,cr,
  64.         sl,sl1,sl2,sl3,
  65.         slA,slB,
  66.         clow,chigh,
  67.         but1,but2;
  68.  
  69.      static char *CY_0[] = {"NORMAL","RANGE","SPECIAL",NULL};
  70.      static char *CY_1[] = {"HEAD OFF","HEAD TOP","HEAD BOT",NULL};
  71.      static char *CY_2[] = {"QUIET OFF","QUIET ON",NULL};
  72.  
  73.      init();
  74.  
  75.  
  76.           /*------------------------------*/
  77. app = ApplicationObject,
  78. MUIA_Application_Title      , "Keyboard",
  79. MUIA_Application_Version    , "$VER: Keyboard 0.002 (28 Feb 1999)",
  80. MUIA_Application_Copyright  , "© 1999 Calogero Calì",
  81. MUIA_Application_Author     , "Calogero Calì",
  82. MUIA_Application_Description, "Keyboard custom class.",
  83. MUIA_Application_Base       , "Keyboard",
  84. SubWindow, window = WindowObject,
  85.      MUIA_Window_Title, "Keyboard custom class",
  86.      MUIA_Window_ID   , MAKE_ID('C','L','S','1'),
  87.      WindowContents, VGroup,
  88.                 Child, ColGroup(2),
  89.                      Child, cq = Cycle(CY_2),
  90.                      Child, cr = SimpleButton("Refresh"),
  91.                 End,
  92.  
  93.                 Child, ColGroup(2),
  94.                      Child, ColGroup(2),
  95.                           Child, CLabel("KeyRelease"),  Child,  sl  = TextObject,MUIA_Text_Contents," ",End,
  96.                           Child, CLabel("KeyCurrent"),  Child,  sl1 = TextObject,MUIA_Text_Contents," ",End,
  97.                           Child, CLabel("From"),        Child,  sl2 = TextObject,MUIA_Text_Contents," ",End,
  98.                           Child, CLabel("To"),          Child,  sl3 = TextObject,MUIA_Text_Contents," ",End,
  99.                      End,
  100.                      Child, ColGroup(2),
  101.                           Child, CLabel("Down"),       Child,  slA = Slider(0,131,0),
  102.                           Child, CLabel("Up"),         Child,  slB = Slider(0,131,0),
  103.  
  104.                           Child, CLabel("Low  note:"),       Child,  clow  = TextObject,MUIA_Text_Contents," ",End,
  105.                           Child, CLabel("High note:"),       Child,  chigh = TextObject,MUIA_Text_Contents," ",End,
  106.                      End,
  107.                 End,
  108.                 Child, HGroup,
  109.                      GroupFrame,
  110.                      MUIA_Group_HorizSpacing, 2,
  111.                      Child,but1 = SimpleButton("Reset"),
  112.                      Child,but2 = SimpleButton("Range 12~24"),
  113.                      Child,  cx = Cycle(CY_0),
  114.                      Child,  ch = Cycle(CY_1),
  115.                 End,
  116.  
  117.                 Child, VGroup,
  118.                      Child, ScrollgroupObject,
  119.                           MUIA_Scrollgroup_FreeVert,FALSE,
  120.                           MUIA_Scrollgroup_Contents, PianoKeyboard = PkbObject,
  121.                                 VirtualFrame,
  122.                                 MUIA_Background, MUII_BACKGROUND,
  123.                                 MUIA_Pkb_Octv_Start, 1,
  124.                                 MUIA_Pkb_Octv_Range, 11,
  125.                                 MUIA_Pkb_Octv_Name,TRUE,
  126.                                 MUIA_Pkb_Octv_Base, -2,
  127.                                 MUIA_Pkb_ExcludeHigh, 4,
  128.                           End,
  129.                      End,
  130.  
  131.                      Child, ScrollgroupObject,
  132.                           MUIA_Scrollgroup_FreeVert,FALSE,
  133.                           MUIA_Scrollgroup_Contents, PKbsmall = PkbObject,
  134.                                 VirtualFrame,
  135.                                 MUIA_Background, MUII_BACKGROUND,
  136.                                 MUIA_Pkb_Octv_Start, 1,
  137.                                 MUIA_Pkb_Octv_Range, 11,
  138.                                 MUIA_Pkb_Octv_Name,TRUE,
  139.                                 MUIA_Pkb_Octv_Base, -2,
  140.                                 MUIA_Pkb_ExcludeHigh, 4,
  141.                                 MUIA_Pkb_Type, MUIV_Pkb_Type_SMALL,
  142.                           End,
  143.                      End,
  144.                 End,
  145.  
  146.           End, /* VGroup */
  147.      End,  /* WindowObject */
  148. End; /* ApplicationObject */
  149.           /*------------------------------*/
  150.  
  151.  
  152.      if (!app)
  153.           fail(app,"Failed to create Application.");
  154.  
  155.  
  156.      DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  157.                  app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  158.  
  159.  
  160.      DoMethod(cx,MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,
  161.                  PianoKeyboard, 3,
  162.                  MUIM_Set, MUIA_Pkb_Mode, MUIV_TriggerValue);
  163.      DoMethod(cx,MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,
  164.                  PKbsmall, 3,
  165.                  MUIM_Set, MUIA_Pkb_Mode, MUIV_TriggerValue);
  166.  
  167.      DoMethod(ch,MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,
  168.                  PianoKeyboard, 3,
  169.                  MUIM_Set, MUIA_Pkb_Range_Head, MUIV_TriggerValue);
  170.      DoMethod(ch,MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,
  171.                  PKbsmall, 3,
  172.                  MUIM_Set, MUIA_Pkb_Range_Head, MUIV_TriggerValue);
  173.  
  174.           /*Quiet */
  175.      DoMethod(cq,MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,
  176.                  PianoKeyboard,3,
  177.                  MUIM_Set,MUIA_Pkb_Quiet,MUIV_TriggerValue);
  178.  
  179.           /*Refresh */
  180.      DoMethod(cr,MUIM_Notify,MUIA_Pressed, FALSE,
  181.                  PianoKeyboard,1,MUIM_Pkb_Refresh);
  182.  
  183.           /*Reset */
  184.      DoMethod(but1,MUIM_Notify,MUIA_Pressed, FALSE, 
  185.                  PianoKeyboard,1,MUIM_Pkb_Reset);
  186.      DoMethod(but1,MUIM_Notify,MUIA_Pressed, FALSE, 
  187.                  PKbsmall,1,MUIM_Pkb_Reset);
  188.  
  189.           /*Refresh */
  190.      DoMethod(but2,MUIM_Notify,MUIA_Pressed, FALSE, 
  191.                  PianoKeyboard,3,
  192.                  MUIM_Pkb_Range,24,12);
  193.  
  194.           /* Down */
  195.      DoMethod(slA,MUIM_Notify,MUIA_Numeric_Value, MUIV_EveryTime,
  196.                  PianoKeyboard,3,
  197.                  MUIM_Set,MUIA_Pkb_Key_Press,MUIV_TriggerValue);
  198.  
  199.           /* Up */
  200.      DoMethod(slB,MUIM_Notify,MUIA_Numeric_Value, MUIV_EveryTime,
  201.                  PianoKeyboard,3,
  202.                  MUIM_Set,MUIA_Pkb_Key_Release,MUIV_TriggerValue);
  203. //-------------------------------------------------------------------------------
  204.           /* KeyRelease*/
  205.      DoMethod(PianoKeyboard,MUIM_Notify,MUIA_Pkb_Key_Release, MUIV_EveryTime,
  206.                  sl, 4,
  207.                  MUIM_SetAsString,MUIA_Text_Contents,"%ld",MUIV_TriggerValue);
  208.  
  209.           /* KeyCurrent */
  210.      DoMethod(PianoKeyboard,MUIM_Notify,MUIA_Pkb_Current,    MUIV_EveryTime,
  211.                  sl1,4,
  212.                  MUIM_SetAsString,MUIA_Text_Contents,"%ld",MUIV_TriggerValue);
  213.  
  214.           /* From */
  215.      DoMethod(PianoKeyboard,MUIM_Notify,MUIA_Pkb_Range_Start,MUIV_EveryTime,
  216.                  sl2,4,
  217.                  MUIM_SetAsString,MUIA_Text_Contents,"%ld",MUIV_TriggerValue);
  218.  
  219.           /* To */
  220.      DoMethod(PianoKeyboard,MUIM_Notify,MUIA_Pkb_Range_End,  MUIV_EveryTime,
  221.                  sl3,4,
  222.                  MUIM_SetAsString,MUIA_Text_Contents,"%ld",MUIV_TriggerValue);
  223. //-------------------------------------------------------------------------------
  224.  
  225.      {
  226.           ULONG *l;
  227.           ULONG *h;
  228.           static char buf[20];
  229.  
  230.           get(PianoKeyboard,MUIA_Pkb_Low,&l);
  231.           sprintf(buf,"%ld",l);
  232.           set(clow ,MUIA_Text_Contents,buf);
  233.  
  234.           get(PianoKeyboard,MUIA_Pkb_High,&h);
  235.           sprintf(buf,"%ld",h);
  236.           set(chigh,MUIA_Text_Contents,buf);
  237.      }
  238.  
  239.      set(window,MUIA_Window_Open,TRUE);
  240.      {
  241.           ULONG sigs = 0;
  242.           while (DoMethod(app,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit){
  243.                 if (sigs) {
  244.                      sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  245.                      if (sigs & SIGBREAKF_CTRL_C) break; }
  246.           }
  247.      }
  248.      set(window,MUIA_Window_Open,FALSE);
  249.  
  250.  
  251. /*
  252. ** Shut down...
  253. */
  254.  
  255.      MUI_DisposeObject(app);             /* dispose all objects. */
  256.      fail(NULL,NULL);                    /* exit, app is already disposed. */
  257.  
  258.      return(0);
  259. }
  260.  
  261. void
  262. init()
  263. {
  264.      if ( !(MUIMasterBase = OpenLibrary("muimaster.library",17L)) )
  265.           fail(NULL,"required muimaster.library");
  266.  
  267. }
  268.  
  269. void
  270. fail(APTR app,char *str)
  271. {
  272.      if (app)           MUI_DisposeObject(app);
  273.      if (str)           puts(str);
  274.      if (MUIMasterBase) CloseLibrary(MUIMasterBase);
  275.  
  276.      exit(0);
  277. }
  278.  
  279.